﻿var viewModel;
var viewModelJs;
var participants = new Array();
var eventId = 2;
$(document).ready(
    //downloadParticipants(eventId)
    downloadEvents()
    );

//function downloadParticipants(index) {
//    // Send an AJAX request
//    var viewModelJsParticipants;
//    $.getJSON("/api/Participants/" + index,
//        function (data) {
//            // On success, 'data' contains the new data.
//            viewModelJsParticipants = { Participants: data};
//        })
//    .success(function () { toastr.success('Download complete'); })
//    .error(function () { toastr.error('No data available'); })
//    .complete(function () {
//        generateViewModel(viewModelJsParticipants);
//    });

//}

function downloadEvents() {
    // Send an AJAX request
    $.getJSON("/api/Event",
        function (data) {
            // On success, 'data' contains the new data.
            viewModelJs = {
                Events: data
            };            
        })
    .success(function () { toastr.success('Event Download complete'); })
    .error(function () { toastr.error('No data available'); })
    .complete(function () {
        generateViewModel(viewModelJs);
    })
}

//function downloadEvents() {
//    // Send an AJAX request
//    $.getJSON("/api/Event",
//        function (data) {
//            // On success, 'data' contains the new data.
//            viewModelJs = {
//                Events: data
//            };            
//        })
//    .success(function () { toastr.success('Event Download complete'); })
//    .error(function () { toastr.error('No data available'); })
//    .complete(function () {
//        for (var i in viewModelJs.Events) {
//            downloadParticipants(viewModelJs.Events[i].EventId, i);
//        };
//        generateViewModel(viewModelJs);
//    })
//}



//function downloadParticipants(index, j) {
//    // Send an AJAX request
//    var viewModelJsParticipants;
//    $.getJSON("/api/Participants/" + index,
//        function (data) {
//            // On success, 'data' contains the new data.
//            viewModelJsParticipants = data;
//            //viewModel = generateViewModel(viewModelJs);
//        })
//    .success(function () { toastr.success('Download complete'); })
//    .error(function () { toastr.error('No data available'); })
//    .complete(function () {
//        participants[index] = viewModelJsParticipants;
//        viewModelJs.Events[j].Participants = participants[index];
//        viewModel.Events()[j].Participants(participants[index]);
//    });
    
//}

